import { Controller, Get, Post, Put, Body, Query, Param, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';
import { SessionService } from './session.service';
import { CreateSessionDto, BaseSessionDto, UpdateSessionDto, QuerySessionDto, ListSessionDto } from './dto/session.dto';
import { ApiDataResponse } from 'src/common/decorators/apiDataResponse.decorator';

@ApiTags('会话表，存储对话会话的基本信息')
@Controller('system/session')
export class SessionController {
  constructor(private readonly sessionService: SessionService) {}

  @ApiOperation({ summary: '会话表，存储对话会话的基本信息-创建' })
  @ApiDataResponse(BaseSessionDto)
  // @RequirePermission('system:session:add')
  @Post()
  create(@Body() body: CreateSessionDto) {
    return this.sessionService.create(body);
  }

  @ApiOperation({ summary: '会话表，存储对话会话的基本信息-列表' })
  @ApiDataResponse(ListSessionDto, true, true)
  // @RequirePermission('system:session:list')
  @Get('list')
  findAll(@Query() query: QuerySessionDto) {
    return this.sessionService.findAll(query);
  }

  @ApiOperation({ summary: '会话表，存储对话会话的基本信息-详情' })
  @ApiDataResponse(BaseSessionDto)
  @RequirePermission('system:session:query')
  @Get(':id')
  findOne(@Param('id') id: number) {
    return this.sessionService.findOne(id);
  }

  @ApiOperation({ summary: '会话表，存储对话会话的基本信息-详情' })
  @ApiDataResponse(BaseSessionDto)
  @Get('findBySessionId/:id')
  findBySessionId(@Param('id') id: number) {
    return this.sessionService.findSessionInfo(id);
  }

  @ApiOperation({ summary: '会话表，存储对话会话的基本信息-详情' })
  @ApiDataResponse(BaseSessionDto)
  // @RequirePermission('system:session:query')
  @Get('findLatest/:userId')
  findLatest(@Param('userId') userId: number) {
    return this.sessionService.findLatest(userId);
  }

  @ApiOperation({ summary: '会话表，存储对话会话的基本信息-修改' })
  @ApiDataResponse()
  @RequirePermission('system:session:edit')
  @Put()
  update(@Body() body: UpdateSessionDto) {
    return this.sessionService.update(body);
  }

  @ApiOperation({ summary: '会话表，存储对话会话的基本信息-删除' })
  @ApiDataResponse()
  // @RequirePermission('system:session:remove')
  @Delete(':id')
  remove(@Param('id') id: number) {
    return this.sessionService.remove(id);
  }
}
